package finalfinancialanalyst.business;

import java.io.Serializable;
import java.util.ArrayList;

public class Categories implements Serializable{
    
        private static final long serialVersionUID = 1L;
 
	private ArrayList<String> categories;
        private static Categories instance;
	 
	private Categories() {
                categories = new ArrayList<String>();
	}
        
        public static Categories getInstance() {
            if (instance == null) {
                
                //Try to load from file
                instance = (Categories)IO.loadFromFile(IO.getCategoriesFile());
                if (instance == null) {
                   instance = new Categories();
                   instance.addCategory("Food");
                   instance.addCategory("Medical");
                   instance.addCategory("Rent");
                   instance.addCategory("Salary");
                   instance.addCategory("Entertainment");
                   instance.addCategory("Other");
                }
            }
            return instance;
        }
	 
	public ArrayList getList() {
		return categories;
	}
	 
	public boolean addCategory(String cat) {
		return (categories.add(cat));
	}
	 
	public boolean deleteCategory(String cat) {
		return (categories.remove(cat));
	}
	 
	public boolean isValid(String cat) {
		return categories.contains(cat);
	}
	 
}